package com.magicalcoder.youyamvc.app.adminuser.service.impl;

import com.magicalcoder.youyamvc.app.adminuser.AdminUserConstant;
import com.magicalcoder.youyamvc.app.adminuser.dao.AdminUserProxyDao;
import com.magicalcoder.youyamvc.app.adminuser.dto.AdminUserDto;
import com.magicalcoder.youyamvc.app.adminuser.dto.ModuleAndCategoryDto;
import com.magicalcoder.youyamvc.app.adminuser.service.AdminRoleModulePriorityService;
import com.magicalcoder.youyamvc.app.adminuser.service.AdminUserService;
import com.magicalcoder.youyamvc.app.adminuser.service.AdminUserProxyService;
import com.magicalcoder.youyamvc.app.model.AdminUser;

import com.magicalcoder.youyamvc.core.cache.common.CacheUtil;
import com.magicalcoder.youyamvc.core.common.utils.copy.CopyerSpringUtil;
import com.magicalcoder.youyamvc.core.spring.SpringContainer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.ArrayList;

/**
    代理类 保证了service dao的自动生成 有改动业务 直接写在此类处
*/
/**
* Created by www.magicalcoder.com
* 799374340@qq.com
*/
@Component("adminUserProxyService")
public class AdminUserProxyServiceImpl implements AdminUserProxyService{

    @Resource(name="adminUserProxyDao")
    private AdminUserProxyDao adminUserProxyDao;

    @Resource(name="adminUserService")
    private AdminUserService adminUserService;


    @Override
    public void dealUserCache(String sessionId, AdminUser adminUser) {
        //保护密码
        adminUser.setPassword("***");
        AdminUserDto adminUserDto = new AdminUserDto();
        CopyerSpringUtil.copyProperties(adminUser, adminUserDto);
        //左侧模块
        Long roleId = adminUserDto.getRoleId();
        AdminRoleModulePriorityService adminRoleModulePriorityService = SpringContainer.getBean("adminRoleModulePriorityService", AdminRoleModulePriorityService.class);
        List<ModuleAndCategoryDto> userLeftModules = adminRoleModulePriorityService.userLeftModules(roleId);
        adminUserDto.setUserLeftModules(userLeftModules);
        //存储到缓存
        CacheUtil.resetCache(sessionId, AdminUserConstant.ADMIN_LOGIN_TIMEOUT, adminUserDto);
    }
}
